package com.hll.demo.controller;

import com.hll.demo.pojo.User;
import com.hll.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @author: Mr.Hu
 * @create: 2021-03-14 08:40
 */
@Controller
public class LoginController {

  // 将Service注入Web层,前提是 ServiceImpl类上加了@Service
  // 可以在启动类 DemoApplication中类名旁边的绿叶子图标（放大镜）点击可以查看所有bean
  @Autowired private UserService userService;

  @RequestMapping("/login")
  public String show() {
    return "login";
  }

  @RequestMapping(value = "/loginIn", method = RequestMethod.POST)
  public String login(String name, String password) {
    User userBean = userService.loginIn(name, password);
    if (userBean != null) {
      return "success";
    } else {
      return "error";
    }
  }
}
